<html>
<head>
	<meta charset='utf-8' />
	<title>小区信息助手</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		
		@media screen and (max-width:450px){
			#content{width:98%;margin:0 auto;padding:5px;border:0px solid}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#content{width:450px;margin:0 auto;padding:5px;border:0px solid}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
	</style>
</head>
<body id='content'>
	<div style='height:100%;padding:0px' id='main' class='l1'>

		<h3 style='text-align:center' id='info_title'>通知标题</h3>

		<div id='info_content' style='word-break:break-all'>内容</div>

		<div style='font-size:12px;margin:30px 0;display:none' id='ticketArea'>
			<div style='display:flex'>
				<div style='width:80px'>赞成票：</div>
				<div style='width:60px;text-align:center'><span id='favor'>0</span> 票</div>
			</div>
			<div style='display:flex'>
				<div style='width:80px'>反对票：</div>
				<div style='width:60px;text-align:center'><span id='oppose'>0</span> 票</div>
			</div>

			<div style='text-align:center;margin:20px'>
				<button onclick=_favorOrOppose('favor')>赞成</button>　
				<button onclick=_favorOrOppose('oppose')>反对</button>
			</div>
		</div>

		<div style='font-size:12px;margin:20px 0'>
			<div style='margin-bottom:10px'>发布人：<span id='issueName'>征服</span></div>
			<div>发布日期：<span id='issueTime'>2019-06-28</span></div>
		</div>

		<div style='font-size:12px;margin-bottom:20px'></div>
		<div style='text-align:center;margin:20px'><a href="area_detail.html" style='text-decoration:none'><button>返回</button></a></div>
	</div>



</body>
</html>
<script src='../public/jquery.js'></script>
<script src='../public/fun.js'></script>
<script>
if(!sessionStorage.current_msg_id){
	history.go(-1);
}
var tokenSet = GetCityInfo();
var user_info = GetUserInfo();

//投票操作
function _favorOrOppose(ctype){
	var data = {
		type:'favorOrOppose',
		msg_id:sessionStorage.current_msg_id,
		area_id:sessionStorage.current_area_id,
		ctype:ctype
	}
	AjaxBefore(data,function(res){
		if(!/^{.*}$/.test(res)){
			return;
		}
		var tmp = JSON.parse(res);
		sessionStorage.token1 = tmp.token1;
		switch(tmp.stat){
			case 'err1':case 'err3':A('请求异常！');break;
			case 'err2':A('不能重复投票！');break;
			case 'ok':
				A('投票成功！');
				location.reload();
				break;
		}
		C(res);
	});
}


//获取小区指定信息详情
function GetMsg(){
	var msg_id = sessionStorage.current_msg_id;
	var area_id = sessionStorage.current_area_id;
	var data = {
		type:'GetMsg',
		msg_id:msg_id,
		area_id:area_id
	}
	AjaxBefore(data,function(res){
		if(!/^{.*}$/.test(res)){
			A('数据异常！');
			history.go(-1);
			return;
		}
		var tmp = JSON.parse(res);
		sessionStorage.token1 = tmp.token1;
		switch(tmp.stat){
			case 'err1':
			case 'err2':
				A('数据异常!');
				history.go(-1);
				break;
			case 'ok':
				ParseData(tmp.data);
				break;
		}
	});
}
function ParseData(data){
	C(data);
	$('#info_title').text(data.info_title);
	$('#info_content').text(data.info_content);
	$('#issueName').text(data.openid);
	$('#issueTime').text(StampToYmd(parseInt(data.time)*1000,1));
	if(data.type == 'ticket'){	//投票
		$('#ticketArea').show();
		_getTicket();
	}

}


//获取投票数
function _getTicket(){
	var msg_id = sessionStorage.current_msg_id;
	var area_id = sessionStorage.current_area_id;
	var data = {
		type:'getTicket',
		msg_id:msg_id,
		area_id:area_id
	}
	AjaxBefore(data,function(res){
		if(!/^{.*}$/.test(res)){
			return;
		}
		var tmp = JSON.parse(res);
		sessionStorage.token1 = tmp.token1;
		_parseTicket(tmp.data);
	});
}

//解析投票数据
function _parseTicket(data){
	for(var i=0;i<data.length;i++){
		if(data[i].type == 'favor'){
			$('#favor').text(data[i].count);
		}
		if(data[i].type == 'oppose'){
			$('#oppose').text(data[i].count);
		}
	}
}


$(function(){
	GetMsg();
});
</script>